home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-15 | 6.5 KB | 226 lines | [TEXT/CWIE] |
- // Source for CHelpAttach class
-
- #include "CHelpAttach.h"
- #include "CBalloonApp.h"
-
- #include <LControl.h>
- #include <LPane.h>
- #include <LStream.h>
-
- #include <UEnvironment.h>
-
- // __________________________________________________________________________________________________
- // C L A S S __ C H E L P A T T A C H
- // __________________________________________________________________________________________________
-
- LPane* CHelpAttach::sHelpPane = nil;
-
- // C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S
-
- CHelpAttach* CHelpAttach::CreateHelpAttachStream(LStream *inStream)
- {
- return new CHelpAttach(inStream);
- }
-
- // Default constructor
- CHelpAttach::CHelpAttach(short strId, short index)
- : LAttachment(msg_ShowHelp, true)
- {
- // Check for availablity of Balloon Help
- mHasBalloonHelp = UEnvironment::HasGestaltAttribute(gestaltHelpMgrAttr,gestaltHelpMgrPresent);
-
- // Cache the resource info
- mStrId = strId;
- mIndex = index;
- }
-
- CHelpAttach::CHelpAttach(LStream *inStream)
- : LAttachment(inStream)
- {
- // Check for availablity of Balloon Help
- mHasBalloonHelp = UEnvironment::HasGestaltAttribute(gestaltHelpMgrAttr,gestaltHelpMgrPresent);
-
- // Always force to our message
- mMessage = msg_ShowHelp;
-
- // Cache the resource info
- inStream->ReadData(&mStrId, sizeof(mStrId));
- inStream->ReadData(&mIndex, sizeof(mIndex));
- }
-
-
- // O T H E R M E T H O D S ____________________________________________________________________________
-
- // Show help balloon
- void CHelpAttach::ExecuteSelf(MessageT inMessage, void *ioParam)
- {
- // Only do if help is present and Balloons are on
- if (!mHasBalloonHelp || !::HMGetBalloons())
- {
- sHelpPane = nil;
- return;
- }
-
- // Check for same pane and same balloon
- if (((LPane*) ioParam == sHelpPane) && ::HMIsBalloon() && SameBalloon(ioParam))
- return;
-
- // Remove any old balloon
- if (::HMIsBalloon())
- ::HMRemoveBalloon();
-
- // Fill in Help manager record
- HMMessageRecord aHelpMsg;
- FillHMRecord(aHelpMsg, ioParam);
-
- // Get hot rect so that balloon help automatically removes the balloon if it
- // moves out of the pane
- Rect hotRect;
- ((LPane*) ioParam)->CalcPortFrameRect(hotRect);
- ((LPane*) ioParam)->PortToGlobalPoint(topLeft(hotRect));
- ((LPane*) ioParam)->PortToGlobalPoint(botRight(hotRect));
-
- // Set tip of balloon to centre of pane
- Point tip = {(hotRect.top + hotRect.bottom)/2,
- (hotRect.left + hotRect.right)/2};
-
- // Show the balloon
- OSErr err =::HMShowBalloon(&aHelpMsg, tip, &hotRect, nil, 0, 0, kHMRegularWindow);
-
- // If there was an error set the cached pane to nil to force the balloon
- // to be redrawn the next time AdjustCursor is called. This is neccessary because
- // sometimes the mouse is moving too quick for help manager and balloon fails to draw.
- sHelpPane = (err ? nil : (LPane*) ioParam);
- }
-
- // Fill in the HMMessageRecord
- void CHelpAttach::FillHMRecord(HMMessageRecord &theHelpMsg, void *ioParam)
- {
- // Fill in Help manager record
- theHelpMsg.hmmHelpType = khmmStringRes;
- theHelpMsg.u.hmmStringRes.hmmResID = mStrId;
- theHelpMsg.u.hmmStringRes.hmmIndex = mIndex;
-
- mCurrentIndex = theHelpMsg.u.hmmStringRes.hmmIndex;
- }
-
- // Will display same balloon?
- Boolean CHelpAttach::SameBalloon(void *ioParam)
- {
- // Save for compare
- short current = mCurrentIndex;
-
- // Find out what str index will be used now
- HMMessageRecord aHelpMsg;
- FillHMRecord(aHelpMsg, ioParam);
-
- // Compare
- return (mCurrentIndex == current);
- }
-
- #pragma mark -
-
- // __________________________________________________________________________________________________
- // C L A S S __ C H E L P P A N E A T T A C H
- // __________________________________________________________________________________________________
-
- // C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S
-
- CHelpPaneAttach* CHelpPaneAttach::CreateHelpPaneAttachStream(LStream *inStream)
- {
- return new CHelpPaneAttach(inStream);
- }
-
- // Default constructor
- CHelpPaneAttach::CHelpPaneAttach(short strId, short index_enabled, short index_disabled)
- : CHelpAttach(strId, index_enabled)
- {
- // Cache the resource info
- mEnabledIndex = index_enabled;
- mDisabledIndex = index_disabled;
- }
-
- CHelpPaneAttach::CHelpPaneAttach(LStream *inStream)
- : CHelpAttach(inStream)
- {
- // Cache the resource info
- mEnabledIndex = mIndex;
- inStream->ReadData(&mDisabledIndex, sizeof(mDisabledIndex));
- }
-
-
- // O T H E R M E T H O D S ____________________________________________________________________________
-
- // Fill in the HMMessageRecord
- void CHelpPaneAttach::FillHMRecord(HMMessageRecord &theHelpMsg, void *ioParam)
- {
- // Fill in Help manager record
- theHelpMsg.hmmHelpType = khmmStringRes;
- theHelpMsg.u.hmmStringRes.hmmResID = mStrId;
-
- // Select help string based on pane state
- if (((LPane*) ioParam)->IsEnabled())
- theHelpMsg.u.hmmStringRes.hmmIndex = mEnabledIndex;
- else
- theHelpMsg.u.hmmStringRes.hmmIndex = mDisabledIndex;
-
-
- mCurrentIndex = theHelpMsg.u.hmmStringRes.hmmIndex;
- }
-
- #pragma mark -
-
- // __________________________________________________________________________________________________
- // C L A S S __ C H E L P P A N E A T T A C H
- // __________________________________________________________________________________________________
-
- // C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S
-
- CHelpControlAttach* CHelpControlAttach::CreateHelpControlAttachStream(LStream *inStream)
- {
- return new CHelpControlAttach(inStream);
- }
-
- // Default constructor
- CHelpControlAttach::CHelpControlAttach(short strId, short index_enabled_on, short index_enabled_off, short index_disabled)
- : CHelpAttach(strId, index_enabled_on)
- {
- // Cache the resource info
- mEnabledOnIndex = index_enabled_on;
- mEnabledOffIndex = index_enabled_off;
- mDisabledIndex = index_disabled;
- }
-
- CHelpControlAttach::CHelpControlAttach(LStream *inStream)
- : CHelpAttach(inStream)
- {
- // Cache the resource info
- mEnabledOnIndex = mIndex;
- inStream->ReadData(&mEnabledOffIndex, sizeof(mEnabledOffIndex));
- inStream->ReadData(&mDisabledIndex, sizeof(mDisabledIndex));
- }
-
-
- // O T H E R M E T H O D S ____________________________________________________________________________
-
- // Fill in the HMMessageRecord
- void CHelpControlAttach::FillHMRecord(HMMessageRecord &theHelpMsg, void *ioParam)
- {
- // Fill in Help manager record
- theHelpMsg.hmmHelpType = khmmStringRes;
- theHelpMsg.u.hmmStringRes.hmmResID = mStrId;
-
- // Select help string based on pane state
- if (((LControl*) ioParam)->IsEnabled())
- {
- if (((LControl*) ioParam)->GetValue())
- theHelpMsg.u.hmmStringRes.hmmIndex = mEnabledOnIndex;
- else
- theHelpMsg.u.hmmStringRes.hmmIndex = mEnabledOffIndex;
- }
- else
- theHelpMsg.u.hmmStringRes.hmmIndex = mDisabledIndex;
-
-
- mCurrentIndex = theHelpMsg.u.hmmStringRes.hmmIndex;
- }